from rest_framework import serializers
from .models import CourseCategory,Course,Teacher
class CourseCategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model=CourseCategory
        fields=('id','name')

class CourseTeacherModelSerializer(serializers.ModelSerializer):
    #课程所属老师的序列化器
    class Meta:
        model=Teacher
        fields=('name','title','signature')

class CourseModelSerializer(serializers.ModelSerializer):
    #课程详情的序列化器
    teacher=CourseTeacherModelSerializer()#老师 1  :  多个课程  1对多  序列化器的嵌套
    # teacher=CourseCategoryModelSerializer(many=True)  #多对1
    class Meta:
        model=Course
        fields=("id","name","course_img","students","lessons","pub_lessons","price","discount_name","real_price","teacher","lesson_list")


class CourseDetailTeacherSerializer(serializers.ModelSerializer):
    #课程列表的老师信息
    class Meta:
        model=Teacher
        fields=["id","name","role","title","signature","brief","image"]

class CourseDetailModelSerializer(serializers.ModelSerializer):
    teacher=CourseDetailTeacherSerializer()
    class Meta:
        model=Course
        fields=["id","name","course_img","students","lessons","pub_lessons","price","real_price","teacher","real_brief","level_name","chapter_list","course_video","active_time"]